package com.cardone.platform.common.service;

import java.util.List;

import lombok.Getter;
import lombok.Setter;

import com.cardone.common.function.ProxyFunction;
import com.cardone.common.util.CollectionUtils;
import com.cardone.context.ContextHolder;
import com.google.common.collect.Lists;

/**
 * 公共服务
 *
 * @author yaohaitao
 *
 */
@Getter
@Setter
public class CommonDefaultService implements CommonService {
	private int padLength = Integer.MAX_VALUE - 1000;

	@Override
	public Object proxyFunction(final String userId, final String proxyFunctionName, final String parameters) {
		return ContextHolder.getBean(ProxyFunction.class, proxyFunctionName).execution(userId, parameters);
	}

	@Override
	public List<String> readListProxyFunctionName() {
		final List<String> proxyFunctionNameList = Lists.newArrayList(ContextHolder.getApplicationContext().getBeanNamesForType(ProxyFunction.class));

		CollectionUtils.sortForLength(proxyFunctionNameList);

		return proxyFunctionNameList;
	}
}